package kiosk;


import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.JScrollPane;
import javax.swing.JOptionPane;
import java.awt.Dimension;
import java.io.*;
/**
 *
 * @author Ragnar
 */
public class GUIProduktListe extends JFrame {

    private ProduktListe produkter;
    private ProduktTabellModel dtm;
    private Admin admin;

    public GUIProduktListe() throws IOException
    {
        hent();
        this.produkter = admin.getProduktListe();
        this.initKomponenter();
    }

    public GUIProduktListe(ProduktListe prod, int id)
    {
        this.setTitle("" + id);
        this.produkter = prod;
        this.initKomponenter();
    }

    private void initKomponenter()
    {
        this.setSize(760, 300);

        
        String col[] = { "Strekkode", "Produktnavn", "Antall Igjen", "Pris" };
        dtm = new ProduktTabellModel(this.produkter, col);
        JTable tbl = new JTable();
        tbl.setModel(dtm);

        JScrollPane jsp = new JScrollPane(tbl);
        jsp.setPreferredSize(new Dimension(760, 200));
        this.add(jsp);
        this.setVisible(true);

    }

    public void hent() throws IOException
    {
        try
        {
            FileInputStream input = new FileInputStream("lister.ser");
            ObjectInputStream in = new ObjectInputStream(input);
            this.admin = (Admin) in.readObject();
            input.close();
            in.close();
            JOptionPane.showMessageDialog(null, "Data hentet");
        }
        catch (Exception e)
        {
            JOptionPane.showMessageDialog(null, e);
        }
    }

    public static void main(String[] args)
    {
        try
        {
            GUIProduktListe v = new GUIProduktListe();
        }
        catch (Exception e)
        {
            
        }
    }

    
}
